package main

import (
	"fmt"
	"gin_management_system/middleware/inject"
	"gin_management_system/models"
	"gin_management_system/pkg/logging"
	"gin_management_system/pkg/setting"
	"gin_management_system/routers"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func init(){
	setting.Setup()
	models.Setup()
	logging.Setup()
	err := inject.LoadCasbinPolicyData()
	if err != nil {
		panic("加载casbin策略数据发生错误: " + err.Error())
	}
}

func main(){
	gin.SetMode(setting.ServerSetting.RunMode)
	routersInit := routers.InitRouter()
	readTimeout := setting.ServerSetting.ReadTimeout
	writeTimeout := setting.ServerSetting.WriteTimeout
	endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
	maxHeaderBytes := 1 << 20

	s := &http.Server{
		Addr:	endPoint,
		Handler:	routersInit,
		ReadTimeout: readTimeout,
		WriteTimeout:	writeTimeout,
		MaxHeaderBytes:	maxHeaderBytes,
	}
	log.Printf("[info] start http server listening %s", endPoint)
	s.ListenAndServe()
}